import { observable, action, toJS } from 'mobx';
import * as planMain from '../../apis/plan/planMain'
import { WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
export default class PlanDetailViewStore {
    @observable spinning = false;
    @observable canEdit = false;
    @observable refreshMark = true;
    @observable category = ''
    @observable emptyArray = [];
    @observable emptyReplaceDatas = [{}]
    showtask = false;
    @observable canView = false;
    @observable customList = [];
    @observable uploadReset = true
    @observable editParams = {

        taskarray: [],//相关任务
        docarray: [],//相关文档
        wfarray: [],//相关流程
        crmarray: [],//相关客户
        projectarray: [],//相关项目
        filearray: [],//附件

    };
    @observable fblist = [];//反馈list
    @observable fblastcount = 0;//剩余反馈数量
    @observable feedbackContent = '';//反馈内容
    lastfeedbackid = '';
    //获取页面元素值
    @action
    getDetailView = params => {
        this.spinning = true;
        //页面重新渲染时 清空任务反馈
        this.feedbackContent = '';
        this.fblastcount = 0;
        this.fblist = [];
        this.lastfeedbackid = '';
        this.editParams = {}
        planMain.getDetailView(params).then(action((data) => {
            if (data.api_status == 1) {
                this.editParams = data.mapdata;
                this.showtask = data.showtask;
                this.fblist = data.fblist || [];
                this.fblastcount = data.lastcount || 0;
                if (data.fblist) {
                    this.lastfeedbackid = data.fblist[data.fblist.length - 1].lastid;
                }
                this.customList = data.customList || [];
                this.canEdit = data.canedit;
                this.canView = data.canedit;
                this.category = data.category;
            }
            this.spinning = false;
        }));
    }
    //保存 添加反馈
    @action
    saveDetailView = params => {
        planMain.saveDetailView(params).then(action((data) => {
            if (params.operation == 'add_feedback') {
                if (data.api_status == "1") {
                    this.feedbackContent = '';
                    this.fblist.unshift(data.datamap);
                }
            } else {
                if (params.doback) {
                    params.doback();
                }
            }
        }));
    }
    //得到反馈
    @action
    getFbInfo = params => {
        if (this.editParams.viewdate) {
            params.viewdate = this.editParams.viewdate;
        }
        params.lastid = this.lastfeedbackid;
        params.lastcount = this.fblastcount;
        params.operation = 'get_feedback';
        planMain.getDetailView(params).then(action((data) => {
            if (data.api_status == 1) {
                this.fblist = this.fblist.concat(data.datas);
                this.fblastcount = data.lastcount;
                this.lastfeedbackid = data.datas[data.datas.length - 1].lastid;
            }
        }));
    }
    @action
    setValue = (f, v) => {
        this[f] = v
    }
    @action
    removeFromFileArray=(index)=>{
        this.editParams['filearray'].splice(index,1)
    }
    @action ('看文档')
    viewDocFiled = params => {
      planMain.viewDocFiled (params).then (
        action (data => {
          if (data.api_status == '1') {
            params.doback ();
          }
        })
      );
    };
  
}